package sysmgr.dao.impl;

import commmon.db.DbConnection;
import commmon.db.JdbcConnectionPool;
import sysmgr.bean.BookCommodity;
import sysmgr.bean.Page;
import sysmgr.bean.StaffAddress;
import sysmgr.bean.StaffOrder;
import sysmgr.dao.AddressDao;
import sysmgr.dao.StaffOrderDao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author 22246
 */
public class StaffOrderDaoImpl implements StaffOrderDao {

    /**
     * 保存数据
     *
     * @param staffDate 用户数据对象
     * @return 是否保存成功
     */
    @Override
    public boolean saveStaffDate(StaffOrder staffDate) {
        return false;
    }

    /**
     * 删除数据
     *
     * @param staffDate 用户数据对象
     * @return 是否保存成功
     */
    @Override
    public boolean removeStaffDate(StaffOrder staffDate) {
        return false;
    }

    /**
     * 查询所有的用户数据对象，携带分页
     *
     * @param page 分页对象
     * @return 封装了用户数据对象的集合
     */
    @Override
    public List<StaffOrder> queryStaffDateAll(Page page, StaffOrder staffOrder) {
        try {
            //创建连接对象
            Connection conn= JdbcConnectionPool.getConnection();
            String sql="select * from staff_order";
            //进行条件的拼接,判断如果不为null且不为空字符串
            if(!"".equals(staffOrder.getStaffId()) && staffOrder.getStaffId() != null)  {
                //如果传入了条件，就将条件拼接到后面，否则就不拼接
                sql += " where staffid like '%" + staffOrder.getStaffId() + "%'";
            }
            ResultSet q = (ResultSet) DbConnection.toExecuteMethod(conn, sql, null, "Q");
            Object staff1= DbConnection.getObjectFromResultSetList(q, StaffOrder.class);
            List<StaffOrder> staffDateList = (List<StaffOrder>) staff1;
            if(staff1!=null){
                return staffDateList;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    public boolean deleteStaffDateAll(StaffOrder staffOrder) {
        try {
            //创建连接对象
            Connection conn= JdbcConnectionPool.getConnection();
            String sql="delete from staff_order where id =" + staffOrder.getId();
            Integer d = (Integer) DbConnection.toExecuteMethod(conn, sql, null, "D");
            if (d == 1){
                return true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public boolean updateStaffDateAll(StaffOrder staffOrder) {
        try {
            //创建连接对象
            Connection conn = JdbcConnectionPool.getConnection();
            String sql = "update staff_order set status ='"+staffOrder.getStatus()+"' where id ="+staffOrder.getId();
            Integer u = (Integer) DbConnection.toExecuteMethod(conn, sql, null, "U");
            if (u == 1){
                return true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
}
